import Cookies from 'js-cookie'
const TokenKey = 'zhyq_token'
const UserName = 'zhyq_username'
const Password = 'zhyq_password'
const UUID = 'zhyq_uuid'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token, { expires: 7 })
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUserInfo() {
  const username = localStorage.getItem(UserName)
  const password = localStorage.setItem(Password)
  const uuid = localStorage.removeItem(UUID)
  return { username, password, uuid }
}

export function setUserInfo({ username, password, uuid }) {
  localStorage.setItem(UserName, username)
  localStorage.setItem(Password, password)
  localStorage.setItem(UUID, uuid)
}

export function removeUserInfo() {
  localStorage.removeItem(UserName)
  localStorage.removeItem(Password)
  localStorage.removeItem(UUID)
}
